package com.xinshujia.controller;

import com.xinshujia.entity.ThresholdEntity;
import com.xinshujia.response.RespResult;
import com.xinshujia.service.FunctionService;
import org.springframework.web.bind.annotation.*;

/**
 * *************************************
 * *   @author: 野狼上校               **
 * *   @since: 2024-07-19 15:33       **
 * *   @version: 1.0                  **
 * *************************************
 * <p>
 *     与硬件交互的控制器
 */
@RestController
@RequestMapping("function")
public class FunctionController {
    private final FunctionService functionService;

    public FunctionController(FunctionService functionService) {
        this.functionService = functionService;
    }

    /**
     * 关闭/开启采集
     * </p>
     * @param deviceGuid 设备GUID
     * @param operateType 操作类型 (0: 关闭采集， 1: 开启采集)
     */
    @GetMapping("collectOperate")
    public RespResult collectOperate(@RequestParam("deviceGuid") String deviceGuid, @RequestParam("operateType") Integer operateType) {
        Boolean flag = functionService.collectOperate(deviceGuid, operateType);
        return flag ? RespResult.OK() : RespResult.Fail();

    }

    /**
     * 关闭/开启/清除报警
     * @param deviceGuid 设备GUID
     * @param operateType 操作类型 (0: 关闭报警， 1: 开启报警, 2: 清除报警)
     */
    @GetMapping("alarmOperate")
    public RespResult alarmOperate(@RequestParam("deviceGuid") String deviceGuid, @RequestParam("operateType") Integer operateType) {
        Boolean flag = functionService.alarmOperate(deviceGuid, operateType);
        return flag ? RespResult.OK() : RespResult.Fail();
    }

    /**
     * 查询阈值
     * todo 具体用到再写
     */

    /**
     * 修改阈值
     * todo 只能向上修改（上线时再加）
     */
    @GetMapping("updateThreshold")
    public RespResult updateThreshold(@RequestBody ThresholdEntity thresholdEntity) {
        Boolean flag = functionService.updateThreshold(thresholdEntity);
        return flag ? RespResult.OK() : RespResult.Fail();
    }
}
